package com.vipboot.framework.core.util.mdc;

import org.slf4j.MDC;

import java.util.concurrent.*;

public class MdcScheduledThreadPoolExecutor extends ScheduledThreadPoolExecutor {
    public MdcScheduledThreadPoolExecutor(int corePoolSize) {
        super(corePoolSize);
    }

    public MdcScheduledThreadPoolExecutor(int corePoolSize, ThreadFactory threadFactory) {
        super(corePoolSize, threadFactory);
    }

    public MdcScheduledThreadPoolExecutor(int corePoolSize, RejectedExecutionHandler handler) {
        super(corePoolSize, handler);
    }

    public MdcScheduledThreadPoolExecutor(int corePoolSize, ThreadFactory threadFactory, RejectedExecutionHandler handler) {
        super(corePoolSize, threadFactory, handler);
    }

    @Override
    public <T> Future<T> submit(Callable<T> task) {
        return super.submit(MdcThreadWrapUtil.wrap(task, MDC.getCopyOfContextMap()));
    }

    @Override
    public <T> Future<T> submit(Runnable task, T result) {
        return super.submit(MdcThreadWrapUtil.wrap(task, MDC.getCopyOfContextMap()), result);
    }

    @Override
    public Future<?> submit(Runnable task) {
        return super.submit(MdcThreadWrapUtil.wrap(task, MDC.getCopyOfContextMap()));
    }

    @Override
    public void execute(Runnable command) {
        super.execute(MdcThreadWrapUtil.wrap(command, MDC.getCopyOfContextMap()));
    }
}
